package com.tifa.vote.controller;

import com.tifa.vote.bean.User;
import com.tifa.vote.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname ShowVoteController
 * @Description
 * @Date 2022/6/15 12:46
 * @Created by hengyuan
 */
@Controller
public class ShowVoteController {

  @Autowired
  UserService userService;

  @RequestMapping("/show_users")
  public String getUsers(Model model) {
    model.addAttribute("users", userService.getUsers());
    model.addAttribute("user", new User());
    return "users";
  }

  @RequestMapping("/add_user")
  public String addUSer(@ModelAttribute User user, Model model) {
    userService.addUser(user);
    return "redirect:/show_users";
  }
}
